package com.xique.door.api.factory;

import com.xique.common.core.web.domain.AjaxResult;
import com.xique.door.api.RemoteElevatorService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @author shd
 * @create 2022/3/10 15:28
 */
@Component
public class RemoteElevatorFallbackFactory implements FallbackFactory<RemoteElevatorService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteElevatorFallbackFactory.class);

    @Override
    public RemoteElevatorService create(Throwable throwable) {

        log.error("门禁服务调用失败:{}", throwable.getMessage());

        return new RemoteElevatorService() {

            @Override
            public AjaxResult syncEvent() {
                return AjaxResult.error("同步事件失败:" + throwable.getMessage());
            }

            @Override
            public AjaxResult syncRun() {
                return AjaxResult.error("同步运行集合失败:" + throwable.getMessage());
            }

            @Override
            public AjaxResult syncReport() {
                return AjaxResult.error("同步运行统计失败:" + throwable.getMessage());
            }
        };
    }
}
